package com.xiyue.leaspring;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;

public class SpELFirstDemo23 {

	/**
	 * 采用Set集合也同样可以使用，实际上这一项功能相当于弥补了Set集合无法通过索引获取数据的缺陷。
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		Map<String,String> map = new HashMap<String,String>();
		map.put("xiyuwe0","dasdasd1");
		map.put("xiyuwe1","dasdasd2");
		map.put("xiyuwe2","dasdasd3");
		map.put("xiyuwe3","dasdasd4");
		String str = "#allData[xiyuwe2]";//定义表达式
		ExpressionParser parser = new SpelExpressionParser();
		Expression exp = parser.parseExpression(str);
		EvaluationContext context = new StandardEvaluationContext();
		context.setVariable("allData",map);
		String result = exp.getValue(context,String.class);//获取集合
		System.out.println(result);
	}

}
